package main

import (
	"errors"
	"net"
	"net/rpc"
	"net/rpc/jsonrpc"
)

type DemoService struct{}

type Args struct {
	A, B int
}

func (DemoService) Div(args Args, result *float64) error {

	if args.B == 0 {

		return errors.New("by zero /")
	}

	*result = float64(args.A) / float64(args.B)

	return nil
}

func main() {

	//var aaa [] byte = make([]byte, 1024*8)

	/*decoder := json.NewDecoder(strings.NewReader("{\"name\",\"小王吧\"}"))

	var aa map[string]string = make(map[string]string,1024)

	decoder.Decode(&aa)

	fmt.Println(aa)*/

	rpc.Register(DemoService{})


   listener, err := net.Listen("tcp", ":1234")

   if  err != nil{

	   print(err)

   }

   for true {

	   conn, err := listener.Accept()

	   if  err != nil{

		   print(err)

	   }

	   go jsonrpc.ServeConn(conn)
   }

}
